package com.ibiaoke.customer.service;

import com.ibiaoke.common.consts.CommonConsts;
import com.ibiaoke.common.utils.AssertUtils;
import com.ibiaoke.customer.entity.PtFightGroupExample;
import org.springframework.beans.factory.annotation.Autowired;
import com.ibiaoke.customer.dao.PtFlightGroupDao;
import com.ibiaoke.customer.entity.PtFightGroup;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("fightGroupService")
public class FightGroupServiceImpl implements FightGroupService{

    @Autowired
    private PtFlightGroupDao ptFlightGroupDao;

    @Override
    public PtFightGroup saveFightGroup(PtFightGroup ptFightGroup) {
        return ptFlightGroupDao.savePtFightGroup(ptFightGroup);
    }

    @Override
    public List<PtFightGroup> fightGroup(Integer ptGoodsId, Integer kid) {
        AssertUtils.notNull(ptGoodsId,"拼团商品Id不能为空");
        AssertUtils.notNull(kid,"开团人Id不能为空");
        return ptFlightGroupDao.fightGroup(ptGoodsId,kid);
    }

    @Override
    public Integer updatePayTypeAndPayMoney(Integer id, Integer payType, Double payMoney) {
        return  ptFlightGroupDao.updatePayTypeAndPayMoney(id,payType,payMoney);
    }

    @Override
    public PtFightGroup getFightGroup(Integer customerId, Integer ptGoodsId, Integer kid) {
        AssertUtils.notNull(customerId,"用户Id不能为空");
        AssertUtils.notNull(ptGoodsId,"拼团商品不能为空");
        AssertUtils.notNull(kid,"开团Id不能为空");
        PtFightGroupExample example = new PtFightGroupExample();
        example.createCriteria()
                .andPayStatusEqualTo(CommonConsts.YES)
                .andUserIdEqualTo(customerId)
                .andPtGoodsIdEqualTo(ptGoodsId)
                .andKidEqualTo(kid);
        return ptFlightGroupDao.getByExample(example);
    }

    @Override
    public Integer deleteFightGroup(Integer pid, Integer isDelete) {
        return  ptFlightGroupDao.deleteFightGroup(pid,isDelete);
    }

    @Override
    public PtFightGroup getFightGroup(Integer pid) {
        return  ptFlightGroupDao.getFightGroup(pid);
    }

    @Override
    public List<PtFightGroup> getFightGroupByKid(Integer Kid) {
        return ptFlightGroupDao.getFightGroupByKid(Kid);
    }
}
